/* 
 * File:   newmain.cpp
 * Author: stephen
 *
 * Created on September 10, 2008, 1:10 PM
 */

#include <iostream>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <ctime>
#include <vector>
#include <fstream>

using namespace std;

int main(int argc, char** argv)
{
    vector < vector<string> > vectMatrix;
    vector <string> vectLine;
    ifstream inFile;
    inFile.open("city-pop2.txt");
    string word;
    int sepCount = 0;
    string SEP = "#", fullWord;
    vector< vector<string> >::iterator iter_row;
    vector<string>::iterator iter_col;
    
    if(!inFile)
    {
        cout << "could not open file\n";
        exit (1);
    }
    else
    {
        
    inFile >> word;
    
    while(word != SEP)       
    {
        while(sepCount < 2)
        {
            if(word != SEP)
            {
                fullWord += (word + " ");
                sepCount = 0;
            }
            else
            {
                vectLine.push_back(fullWord);
                fullWord.clear();
                sepCount++;
            }
            
            if(sepCount < 2)
                inFile >> word;
            
        }
        
        vectMatrix.push_back(vectLine);
        inFile >> word;
        sepCount = 0;
        
        vectLine.clear();
    }
    
    inFile.close();
    
    
    
    for(iter_row = vectMatrix.begin(); iter_row != vectMatrix.end(); iter_row++)
    {
        for(iter_col = (*iter_row).begin(); iter_col != (*iter_row).end(); iter_col++)
        {
            cout << *iter_col << " ";
        }
        
        cout << endl;
    }
    }
    
    
    
    return 0;
}

//bool parseFile()




//double returnFloat(char []);


/*const int MAX_SIZE = 10;

class squareMatrix
{
    public:
        squareMatrix();
        int addMatrix(squareMatrix);
        int getIndexVal(int row, int col);
        void setIndexVal(int row, int col, int value);
        
    private:
        int matrix[MAX_SIZE][MAX_SIZE];
};

squareMatrix::squareMatrix()
{
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
            matrix[row][col] = 0;
    }
}

void squareMatrix::setIndexVal(int row, int col, int value)
{
    matrix[row][col] = value;
}

int squareMatrix::getIndexVal(int row, int col)
{
    return matrix[row][col];
}

int squareMatrix::addMatrix(squareMatrix matrix2)
{
    int total = 0;
    
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
            total += matrix[row][col] + matrix2.getIndexVal(row, col);            
    }
    
    return total;
}

void populateMatrix(squareMatrix &obj1, squareMatrix &obj2);

int main(int argc, char** argv) {
    
    squareMatrix arrNum, arrNum2;
    int sum;
    
    populateMatrix(arrNum, arrNum2);
    
    sum = arrNum.addMatrix(arrNum2);
        
    cout << "Sum of arrNum and arrNum2: " << sum << endl << endl;
    
    
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
        {
            cout << setw(5) << arrNum.getIndexVal(row, col) << " ";
        }
        
        cout << endl;
    }
    
    cout << endl << endl;
    
    
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
        {
            cout << setw(5) << arrNum2.getIndexVal(row, col) << " ";
        }
        
        cout << endl;
    }
    
    return 0;
}

void populateMatrix(squareMatrix &obj1, squareMatrix &obj2)
{
    srand(NULL);
    
    for(int row = 0; row < MAX_SIZE; row++)
    {
        for(int col = 0; col < MAX_SIZE; col++)
        {
            obj1.setIndexVal(row, col, (rand() % 20));
            obj2.setIndexVal(row, col, (rand() % 20));
        }
    }
}
    
    /*int choice;
    int ascNum;
    bool digit;
    
    cout << "Enter a number: ";
    cin >> choice;
    
    if(cin.fail())
    {
        cin.clear();
        cin.ignore(1000, '\n');
        cout << "not an integer\n";
    }
    else
        cout << choice;
}
    
    
    /*digit = checkStringForDigits(choice);
    
    if(digit)
        cout << "not a pure integer";
    else
    {
        ascNum = atoi(choice);
        cout << ascNum << endl;
    }
    
    
        
   return (EXIT_SUCCESS);
}

/*****************************************************************
 *this function ensures the user entered the proper option. 
 *this prevents the program from entering an infinite loop if
 *the user enters a character or a string as an option. It accepts
 *a string parameter, then checks to make sure the user entered
 *a single number (using 'isdigit()'), if it fails this test, then
 *the function returns the default -1 option. if it passes, the 
 *variable is casted using static_cast<int> to an integer to
 *acquire its ASCII value. The switch statement then returns
 *its integer value.
 *****************************************************************

int returnDigit(char choice[])
{     
    bool alpha = false;
    int index = 0, ascNum;
    
    while(choice[index] != '\0'&& !alpha)
    {
        if(!isdigit(choice[index]))
            alpha = true;
        index++;
    }
    
    if(!alpha)
    {
        ascNum = atoi(choice);
        return ascNum;
    }    
    else
        return -1;
}
    
double returnFloat(char choice[])
{
    bool alpha = false, decimal = false;
    int index = 0, ascNum;
    
    while(choice[index] != '\0'&& !alpha)
    {
        if(!isdigit(choice[index]) && choice[index] != '.')
            alpha = true;
        if(choice[index] == '.')
            decimal = true;
        index++;
    }
    
    if(!alpha || (!alpha && decimal))
    {
        ascNum = atoi(choice);
        return ascNum;
    }    
    else
        return -1;
}*/


